package com.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.boot.configurationprocessor.json.JSONObject;

import java.io.Serializable;


/**
 * 用于 HttpClientUtils 请求工具数据传输类
 */
@Data
public class HttpClientJsonResult implements Serializable {

    private int code; //响应码
    private String data; //JSON String 格式响应数据

    public HttpClientJsonResult() {}

    public HttpClientJsonResult(int code) {
        this(code, null);
    }

    public HttpClientJsonResult(int code, String data) {
        this.code = code;
        this.data = data;
    }

    /**
     * 转 JSONObject 对象
     * @return
     */
    @JsonIgnore //不需要返回的 get 方法
    public JSONObject getJSONObject() throws JSONException {
        return new JSONObject(data);
    }

}
